Target_target = "target"


SpellQue = {
	data = {},
}
SpellQue.__index = SpellQue

function SpellQue.new()
	local obj = {
		data = {},
	}

	setmetatable(obj, SpellQue)

	return obj
end


function SpellQue:add(spell, target, pred)
	table.insert(self.data, {
		spell = spell,
		target = target or "target",
		pred = pred,
	})
end


local function cast(u)
	local usable, nomana = IsUsableSpell(u.spell)
	if not usable then
		return false
	end

	local start, duration, enabled = GetSpellCooldown(self.name)
	if start ~= 0 then
		return false
	end

	if u.pred and !u.pred(u.spell) then
		return false
	end

	CastSpellByName(u.spell, u.target)
	return true
end

function SpellQue:cast()
	for _, u in ipairs(self.spellList) do
		-- print('cast spell ', spell.name)
		if cast(u)  then
			-- print('success!!!')
			break
		end
	end
end
